package com.hdu.other.monotonyStack;

import java.io.*;

public class template {
    private static final int MAX_N = 1000000;
    private static final int[] ARR = new int[MAX_N];
    private static final int[] STACK = new int[MAX_N];
    private static final int[][] ANS = new int[MAX_N][2];
    private static int N = 0;

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        StreamTokenizer st = new StreamTokenizer(br);

        while (st.nextToken() != StreamTokenizer.TT_EOF) {
            N = (int) st.nval;
            refresh();
            for (int i = 0; i < N; i++) {
                st.nextToken();
                ARR[i] = (int) st.nval;
            }
            compute();
            for (int i = 0; i < N; i++) {
                pw.println(ANS[i][0] + " " + ANS[i][1]);
            }
        }

        pw.flush();
        br.close();
        pw.close();
    }

    private static void compute() {
        int r = 0;
        for (int i = 0; i < N; i++) {
            if (r == 0 || ARR[i] > ARR[STACK[r - 1]]) {
                STACK[r++] = i;
            }
            else {
                while (r > 0 && ARR[i] <= ARR[STACK[r - 1]]) {
                    int index = STACK[--r];
                    int left = r == 0 ? -1 : STACK[r - 1];
                    ANS[index][0] = left;
                    ANS[index][1] = i;
                }
                STACK[r++] = i;
            }
        }

        while (r > 0) {
            int index = STACK[--r];
            int left = r == 0 ? -1 : STACK[r - 1];
            ANS[index][0] = left;
            ANS[index][1] = -1;
        }

        for (int i = N - 2; i >= 0; i--) {
            if (ANS[i][1] != -1 && ARR[ANS[i][1]] == ARR[i]) {
                ANS[i][1] = ANS[ANS[i][1]][1];
            }
        }
    }


    static void refresh() {
        for (int i = 0; i < N; i++) {
            ANS[i][0] = 0;
            ANS[i][1] = 0;
        }
    }

}
